package com.schoolET.mapper;

import com.schoolET.entity.Region;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 区域信息 Mapper 接口
 * </p>
 *
 * @author le
 * @since 2024-05-31
 */
@Mapper
public interface RegionMapper extends BaseMapper<Region> {

    @Select("select * from region where position = #{position} and flag = 0")
    Region getRegion(String position);

    @Select("select t1.* from region t1 \n" +
            "LEFT JOIN wechat_and_region t2 on t1.id = t2.region_id\n" +
            "LEFT JOIN wechat t3 on t2.wechat_id = t3.id\n" +
            "WHERE\n" +
            "t3.id = #{wechatId} and t2.default_location = 1")
    Region selectRegionByWechatId(Integer wechatId);

    @Select("select t1.* from region t1 \n" +
            "LEFT JOIN wechat_and_region t2 on t1.id = t2.region_id\n" +
            "LEFT JOIN wechat t3 on t2.wechat_id = t3.id\n" +
            "WHERE\n" +
            "t3.open_id = #{openId} and t2.default_location = 1")
    Region selectRegionByOpenId(String openId);

    @Select("select t1.* from region t1 \n" +
            "LEFT JOIN admin_and_region t2 on t1.id = t2.region_id\n" +
            "LEFT JOIN administrators t3 on t2.admin_id = t3.id\n" +
            "WHERE\n" +
            "t3.id = #{adminId}")
    Region selectRegionByAdminId(Integer adminId);

}
